
const tokens = {
  admin: 'admin-token',
  tester: 'tester-token'
}

const users = {
  'admin-token': {
		"userId": 1,
		"username": "admin",
		"name": "管理员",
		"accountNonExpired": false,
		"accountNonLocked": false,
		"credentialsNonExpired": false,
		"enabled": false,
		"roles": [{
			"role": "admin",
			"permissions": {
				"menus": ["menu_weizhiguanli", "menu_zidianguanli", "menu_yonghuguanli", "menu_bumenguanli", "menu_hetongxiangguanli", "menu_hetongguanli", "menu_jueseguanli", "menu_quanxianguanli", "menu_zidianleixingguanli", "menu_gudingzichanguanli", "menu_gongyingshangguanli"],
				"actions": []
			}
		}],
		"permissions": {
			"menus": [],
			"actions": []
		},
		"orgs": ["shishibu", "yunweibu", "root", "caigoubu", "hr"]
	},
  'tester-token': {
		"userId": 12,
		"username": "wangsi",
		"name": "wangsi",
		"accountNonExpired": false,
		"accountNonLocked": false,
		"credentialsNonExpired": false,
		"enabled": false,
		"roles": [{
			"role": "admin",
			"permissions": {
				"menus": ["menu_weizhiguanli", "menu_zidianguanli", "menu_yonghuguanli", "menu_bumenguanli", "menu_hetongxiangguanli", "menu_hetongguanli", "menu_jueseguanli", "menu_quanxianguanli", "menu_zidianleixingguanli", "menu_gudingzichanguanli", "menu_gongyingshangguanli"],
				"actions": []
			}
		}],
		"permissions": {
			"menus": [],
			"actions": []
		},
		"orgs": ["shishibu", "hr"]
	}
}

export default [
  // user login
  {
    url: '/login',
    type: 'post',
    response: config => {
      const { username } = config.body
      const token = tokens[username]

      // mock error
      if (!token) {
        return {
          status: 'failure',
          message: '认证失败'
        }
      }

      return {
        status: 'success',
        data: token
      }
    }
  },

  // get user info
  {
    url: '/auth/api/w/auth/users/me',
    type: 'get',
    response: config => {
      const token = config.get('Authentication')
      const info = users[token]

      return {
        status: 'success',
        data: info
      }
    }
  },

  // user logout
  {
    url: '/logout',
    type: 'post',
    response: _ => {
      return {
        status: 'success',
      }
    }
  }
]
